package database

import (
	"gin.project.template/config"
	"gin.project.template/global"
	"gorm.io/driver/postgres"
	"gorm.io/gorm"
)

func InitPostgres() {
	db, _ := gorm.Open(postgres.Open(config.Conf.PostgresDns), &gorm.Config{})
	pDB, err := db.DB()
	if err != nil {
		global.Logger.Error("postgres init fail")
		panic(err)
	}

	pDB.SetMaxOpenConns(100)
	pDB.SetMaxIdleConns(10)
	global.PostgresDB = db

	global.Logger.Info("postgres init success")
}
